package com.ruoyi.system.service.impl;



import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.SysPythonAddressEntity;
import com.ruoyi.system.mapper.ISysPythonAddressMapper;
import com.ruoyi.system.service.IMpSysPythonAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author <a href="https://fengwenyi.com?fs=mpcg">Erwin Feng</a>
 * @since 2024-01-16
 */
@Service
public class MpSysPythonAddressServiceImpl extends BaseController implements IMpSysPythonAddressService {
    @Autowired
    private ISysPythonAddressMapper iSysPythonAddressMapper;
    @Override
    public SysPythonAddressEntity getAddressById(Integer id) {
        SysPythonAddressEntity sysPythonAddressEntity = iSysPythonAddressMapper.selectById(id);
        return sysPythonAddressEntity;
    }

    @Override
    public List<SysPythonAddressEntity> getAllAddress() {
        List<SysPythonAddressEntity> allAddress = iSysPythonAddressMapper.selectList(new LambdaQueryWrapper<SysPythonAddressEntity>()
                .eq(SysPythonAddressEntity::getDelStatus,0));

        return allAddress;
    }

    @Override
    public List<SysPythonAddressEntity> getAddressesList(Integer parentId, SysPythonAddressEntity sysPythonAddressEntity) {
        List<SysPythonAddressEntity> allAddress = iSysPythonAddressMapper.selectList(new LambdaQueryWrapper<SysPythonAddressEntity>()
                .eq(SysPythonAddressEntity::getParentId,sysPythonAddressEntity.getParentId()));
        return allAddress;
    }


    @Override
    public AjaxResult saveAndUpdateAndDelAddress(SysPythonAddressEntity sysPythonAddressEntity) {
        if (sysPythonAddressEntity.getId()!=null){
            if (sysPythonAddressEntity.getDelStatus()!=0){
                iSysPythonAddressMapper.updateById(sysPythonAddressEntity);
                return success("删除成功");
            }else {
                iSysPythonAddressMapper.updateById(sysPythonAddressEntity);
                return success("修改成功");
            }

        }else {
            iSysPythonAddressMapper.insert(sysPythonAddressEntity);
            return success("添加成功");
        }

    }
}
